package com.example.shopping_mall.base;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.shopping_mall.MainActivity;
import com.example.shopping_mall.R;
import com.example.shopping_mall.adapter.MoreDetailAdapter;
import com.example.shopping_mall.adapter.RecommendMoreAdapter;
import com.example.shopping_mall.bean.BrandManager;
import com.example.shopping_mall.http.ShoppingRequest;
import com.example.shopping_mall.utils.ShoppingUtils;

import java.util.ArrayList;
import java.util.List;

//品牌更多详情
public class RecommendMoreDetailActivity extends AppCompatActivity {

    private static final String TAG = RecommendMoreDetailActivity.class.getSimpleName();
    private ShoppingRequest sr;
    List<BrandManager> managerList;
    RecyclerView recycler;
    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend_more_detail);

        sr = new ShoppingUtils();
        initView();
    }

    private void initView() {
        Intent intent=getIntent();
        int more_detail_id=intent.getExtras().getInt("more_detail_id");
        Log.d(TAG, "init: "+more_detail_id);

        recycler=findViewById(R.id.recommend_more_detail_View);
        recycler.setLayoutManager(new LinearLayoutManager(this));
        managerList=new ArrayList<>();

        sr.requestBrand(more_detail_id, 1, new ShoppingUtils.OnfindPmsBrandRequestListener() {
            @Override
            public void OnfindPmsBrandRequest(BrandManager[] managers) {
                BrandManager manager=new BrandManager();
                manager.setBigPic(managers[more_detail_id].getBigPic());
                manager.setLogo(managers[more_detail_id].getLogo());
                manager.setName(managers[more_detail_id].getName());
                manager.setBrandStory(managers[more_detail_id].getBrandStory());
                managerList.add(manager);

                MoreDetailAdapter adapter=new MoreDetailAdapter(RecommendMoreDetailActivity.this,managerList);
                recycler.setAdapter(adapter);
            }
        });

        //返回上一个页面
        imageView=findViewById(R.id.recommend_more_detail_back);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(RecommendMoreDetailActivity.this, RecommendMoreActivity.class));
            }
        });
    }
}